package rxb.demo.wzycontroller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import rxb.demo.wzyentity.Food;
import rxb.demo.wzyservice.IFoodService;

import java.util.List;

/**
 * Created by Administrator on 2019/12/31 0031.
 */
@Controller
public class foodController {
    @Autowired
    private IFoodService foodService;

    @GetMapping( "/food" )
    public String list(String foodName, Model model) {

        List<Food> foodList = foodService.getAll(foodName);

        model.addAttribute("foods", foodList);

        model.addAttribute("searchName", foodName);

        return "wzyindex/wzyindex";
    }

    @GetMapping("/del")
    public String del(Integer id) {

        foodService.deleteById(id);

        return "redirect:/wzyindex";

    }

    @GetMapping("/delMore")
    public String del2(String ids) {

        //根据:进行切割
        String[] arr = ids.split(":");

        for (String sid : arr) {
            foodService.deleteById(Integer.valueOf(sid));
        }

        return "redirect:/wzyindex";
    }
}
